//
//  QYGTabbarController.m
//  哈哈
//
//  Created by 奇艺果 on 2017/12/25.
//  Copyright © 2017年 奇艺果. All rights reserved.
//

#import "QYGTabbarController.h"
#import "QYGTabBar.h"
#import "QYGNavigationController.h"
#import "QYGRechargeController.h"
#import "QYGMineViewController.h"
#import "QYGHomeViewController.h"

@interface QYGTabbarController ()

@property (nonatomic, weak) QYGHomeViewController *homeVC;
@property (nonatomic, weak) QYGRechargeController *rechargeVc;
@property (nonatomic, weak) QYGMineViewController *mineVC;
@property (nonatomic, assign) BOOL isShow;
@end

@implementation QYGTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
        // 更换tabBar
    [self setUpAllChildViewController];
    if([QYGKeychain isShowPay]){
        [self setValue:[[QYGTabBar alloc] init] forKeyPath:@"tabBar"];
        QYGTabBar *tabar = (QYGTabBar *)self.tabBar;
        WS(weakSelf);
        [tabar setMiddleClickBlock:^ {
            weakSelf.selectedIndex = 1;
        }];
    }else{
        self.tabBar.tintColor = [UIColor qyg_mainColor];
    }
}
- (void)setUserInfo:(QYGUserInfoModel *)userInfo{
    _userInfo = userInfo;
    self.homeVC.userInfo = self.userInfo;
    self.rechargeVc.userInfo = self.userInfo;
    self.mineVC.userInfo = self.userInfo;
}

- (void)setUpAllChildViewController{
    
    QYGHomeViewController *main = [[QYGHomeViewController alloc] init];
    self.homeVC = main;
    QYGNavigationController *nav = [[QYGNavigationController alloc] initWithRootViewController:main];
    [self setUpOneChildViewController:nav
                          normalImage:@"home_nor"
                          selectImage:@"home_sel"
                                title:@"首页"];
    if([QYGKeychain isShowPay]){
        QYGRechargeController *rechargeVc = [[QYGRechargeController alloc] init];
        self.rechargeVc = rechargeVc;
        QYGNavigationController *rechargNav = [[QYGNavigationController alloc] initWithRootViewController:rechargeVc];
        [self setUpOneChildViewController:rechargNav
                              normalImage:@""
                          selectImage:@""
                                title:@"充值"];
    }
    
    
    QYGMineViewController *mineVC = [[QYGMineViewController alloc] init];
    self.mineVC = mineVC;
    QYGNavigationController *mineNav = [[QYGNavigationController alloc] initWithRootViewController:mineVC];
    
    [self setUpOneChildViewController:mineNav
                          normalImage:@"main_mine_nor"
                          selectImage:@"main_mine_sel"
                                title:@"我的"];
    
}


- (void)setUpOneChildViewController:(UIViewController *)viewController normalImage:(NSString *)normalImageUrl selectImage:(NSString *)selectImageUrl title:(NSString *)title
{
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.image = [UIImage imageNamed:normalImageUrl];
    viewController.tabBarItem.selectedImage = [UIImage imageNamed:selectImageUrl];
    [self addChildViewController:viewController];
    
}

@end
